<!DOCTYPE html>
<html lang="zxx">
<head>
    <title>FORT - 个人空间</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta charset="utf-8">

    <!-- External CSS libraries -->
    <link rel="stylesheet" type="text/css" href="/css/bootstrap.min.css">
    <link rel="stylesheet" type="text/css" href="/css/animate.min.css">
    <link rel="stylesheet" type="text/css" href="/css/bootstrap-submenu.css">

    <link rel="stylesheet" type="text/css" href="/css/bootstrap-select.min.css">
    <link rel="stylesheet" type="text/css" href="/css/magnific-popup.css">
    <link rel="stylesheet" href="/css/leaflet.css" type="text/css">
    <link rel="stylesheet" href="/css/map.css" type="text/css">
    <link rel="stylesheet" type="text/css" href="/fonts/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" type="text/css" href="/fonts/flaticon/font/flaticon.css">
    <link rel="stylesheet" type="text/css" href="/fonts/linearicons/style.css">
    <link rel="stylesheet" type="text/css" href="/css/jquery.mCustomScrollbar.css">
    <link rel="stylesheet" type="text/css" href="/css/dropzone.css">
    <link rel="stylesheet" type="text/css" href="/css/slick.css">

    <!-- Custom stylesheet -->
    <link rel="stylesheet" type="text/css" href="/css/style.css">
    <link rel="stylesheet" type="text/css" id="style_sheet" href="/css/skins/default.css">

    <!-- Favicon icon -->
    <link rel="shortcut icon" href="/img/favicon.ico" type="image/x-icon">

    <!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
    <link rel="stylesheet" type="text/css" href="/css/ie10-viewport-bug-workaround.css">

    <!-- Just for debugging purposes. Don't actually copy these 2 lines! -->
    <!--[if lt IE 9]>
    <script src="js/ie8-responsive-file-warning.js"></script><![endif]-->
    <script src="/js/ie-emulation-modes-warning.js"></script>

    <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
    <!--[if lt IE 9]>
    <script src="js/html5shiv.min.js"></script>
    <script src="js/respond.min.js"></script>
    <![endif]-->
    <script src="/js/jquery-2.2.0.min.js"></script>
    <script src="/js/popper.min.js"></script>
    <script src="/js/bootstrap.min.js"></script>
    <script src="/js/bootstrap-submenu.js"></script>
    <script src="/js/rangeslider.js"></script>
    <script src="/js/jquery.mb.YTPlayer.js"></script>
    <script src="/js/bootstrap-select.min.js"></script>
    <script src="/js/jquery.easing.1.3.js"></script>
    <script src="/js/jquery.scrollUp.js"></script>
    <script src="/js/jquery.mCustomScrollbar.concat.min.js"></script>
    <script src="/js/leaflet.js"></script>
    <script src="/js/leaflet-providers.js"></script>
    <script src="/js/leaflet.markercluster.js"></script>
    <script src="/js/dropzone.js"></script>
    <script src="/js/slick.min.js"></script>
    <script src="/js/jquery.filterizr.js"></script>
    <script src="/js/jquery.magnific-popup.min.js"></script>
    <script src="/js/jquery.countdown.js"></script>
    <script src="/js/maps.js"></script>
    <!--<script  src="js/app.js"></script>-->

    <!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
    <script src="/js/ie10-viewport-bug-workaround.js"></script>
    <!-- Custom javascript -->
    <script src="/js/ie10-viewport-bug-workaround.js"></script>
</head>
<body>

<!-- Main header start -->
<header class="main-header fixed-header-2">
    <div class="container">
        <nav class="navbar navbar-expand-lg navbar-light">
            <a class="navbar-brand company-logo" href="/index">
                <img src="/img/logos/black-logo.png" alt="logo">
            </a>
            <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent"
                    aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
                <span class="navbar-toggler-icon"></span>
            </button>
            <div class="collapse navbar-collapse" id="navbarSupportedContent">
                <ul class="navbar-nav header-ml">
                    <li class="nav-item dropdown active">
                        <a class="nav-link " href="/activity" id="navbarDropdownMenuLink">
                            活动广场
                        </a>
                    </li>

                    <li class="nav-item dropdown active" id="myself">

                    </li>

                    <li class="nav-item dropdown active" id="admin_center">

                    </li>

                    <li class="nav-item dropdown megamenu-li">
                        <a class="nav-link " href="/about">关于我们</a>
                    </li>
                    <li class="nav-item dropdown megamenu-li">
                        <a class="nav-link " href="/contact">与管理员联系</a>
                    </li>
                </ul>
                <ul class="navbar-buttons ml-auto d-none d-xl-block d-lg-block">
                    <div>
                        <ul>
                            <li>
                                <div class="dropdown btns">
                                    <a class="dropdown-toggle" data-toggle="dropdown" id="status"></a>
                                    <div class="dropdown-menu">
                                        <a class="dropdown-item" href="/forgot-password">重置密码</a>
                                        <a class="dropdown-item" id="logout">退出</a>
                                    </div>
                                </div>
                            </li>
                        </ul>
                    </div>
                </ul>
            </div>
        </nav>
    </div>
</header>
<!-- Main header end -->

<!-- Dashbord start -->
<div class="dashboard">
    <div class="container-fluid">
        <div class="row" style="height: 100vh">
            <div class="col-lg-2 col-md-12 col-sm-12 col-pad" >
                <div class="dashboard-nav d-none d-xl-block d-lg-block">
                    <div class="dashboard-inner">
                        <h4>账户</h4>
                        <ul>
                            <li class="active"><a href="/my-profile"><i class="flaticon-user"></i>个人中心</a></li>
                            <li><a href="/submit-property"><i class="flaticon-plus"></i>商家认证</a></li>
                        </ul>
                        <h4>活动</h4>
                        <ul>
                            <li><a href="/my-properties"><i class="flaticon-apartment"></i>我参与过的活动</a></li>
                        </ul>
                    </div>
                </div>
            </div>
            <div class="col-lg-9 col-md-12 col-sm-12 col-pad">
                <div class="content-area5">
                    <div class="dashboard-content">
                        <div class="dashboard-list">
                            <h3 class="heading">基本信息</h3>
                            <div class="dashboard-message contact-2 bdr clearfix">
                                <div class="row">
                                    <div class="col-lg-3 col-md-3">
                                        <!-- Edit profile photo -->
                                        <div class="edit-profile-photo">
                                            <img src="/img/default.jpg" alt="profile-photo" class="img-fluid" id="img">
                                        </div>
                                        <form id="uploadForm" enctype="multipart/form-data">
                                            <div class="change-photo-btn">
                                                <div class="photoUpload">
                                                    <span><i class="fa fa-upload"></i> 上传头像</span>
                                                    <input type="file" class="upload" id="file" name="file"
                                                           accept="image/*">
                                                </div>
                                            </div>
                                        </form>
                                    </div>
                                    <div class="col-lg-9 col-md-9">
                                        <form action="#" method="GET" enctype="multipart/form-data">
                                            <div class="row">
                                                <div class="col-lg-12 col-md-12">
                                                    <div class="form-group ">
                                                        <label>用户名</label>
                                                        <input type="text" name="username" class="form-control"
                                                               disabled="disabled" id="username">
                                                    </div>
                                                </div>
                                                <div class="col-lg-12 col-md-12">
                                                    <div class="form-group ">
                                                        <label>用户编号</label>
                                                        <input type="text" name="userNo" class="form-control"
                                                               disabled="disabled" id="userNo">
                                                    </div>
                                                </div>
                                                <div class="col-lg-12 col-md-12">
                                                    <div class="form-group ">
                                                        <label>手机号</label>
                                                        <input type="text" name="mobile" class="form-control"
                                                               disabled="disabled" id="mobile">
                                                    </div>
                                                </div>
                                                <div class="col-lg-12 col-md-12">
                                                    <div class="form-group ">
                                                        <label>邮箱</label>
                                                        <input type="email" name="email" class="form-control"
                                                               disabled="disabled" id="email">
                                                    </div>
                                                </div>
                                                <div class="col-lg-12 col-md-12 col-sm-12">
                                                    <div class="form-group  ">
                                                        <label>个性签名</label>
                                                        <textarea class="form-control" name="info"
                                                                  placeholder="个性签名" id="info"></textarea>
                                                    </div>
                                                </div>
                                                <div class="col-lg-5 ">
                                                    <div class="send-btn">
                                                        <div class="form-group mb-0">
                                                            <label> </label>
                                                            <button type="button" class="btn-md button-theme btn-block"
                                                                    id="update">更新
                                                            </button>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                        </form>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<!-- Dashbord end -->


<script>

    const token = localStorage.getItem("token");

    $(function f() {
        //token存在
        if (token != null && token != '') {
            $.ajax({
                url: "http://localhost:5761/lottery-system-user/user/api/user/testToken",
                // url: "http://localhost:5710/user/api/user/testToken?token=" + token,
                type: "GET",
                beforeSend: function (XMLHttpRequest) {
                    XMLHttpRequest.setRequestHeader("token", token);
                },
                success: function (result) {
                    // console.log(result);
                    if(result.code==999){
                        alert(result.message);
                        localStorage.removeItem("token");
                        localStorage.removeItem("userNo");
                        return window.location.href = "http://localhost/login";
                    }
                    if (result.code == 200) {
                        //正常
                        $("#myself").append("<a class='nav-link' href='/my-profile'>个人中心</a>");
                        var url = result.data.headImgUrl;
                        document.getElementById("status").innerHTML = "<img src=" + url + " alt='avatar' >" + result.data.username;
                        $("#img").attr("src", url);
                        $("#username").val(result.data.username);
                        $("#userNo").val(result.data.userNo);
                        $("#mobile").val(result.data.mobile);
                        $("#email").val(result.data.email);
                        $("#info").val(result.data.info);
                        document.getElementById("img").style.cursor="pointer";
                        $("#img").click(function () {
                            window.open(url);
                        });
                        //退出
                        $("#logout").click(function () {
                            localStorage.removeItem("token");
                            localStorage.removeItem("userNo");
                            window.location.href = "http://localhost/login";
                        });
                        //如果是商家身份，则添加菜单
                        if(result.data.userType==1){
                            $("#admin_center").append("<a class='nav-link ' href='/lottery_management' >管理中心</a>");
                        }
                        return;
                    } else {
                        //token过期或异常
                        localStorage.removeItem("token");
                        localStorage.removeItem("userNo");
                        return window.location.href = "http://localhost/login";
                    }
                }
            });
        } else {
            //token不存在
            return window.location.href = "http://localhost/login";
        }
    });

    var url = null;
    var info = null;

    //选择完文件后就自动上传
    $("#file").change(function () {
        var userNo = $("#userNo").val();
        //使用 HTML5 FormData对象; 使用js原生对象
        // var file = $("#uploadForm")[0];
        var file = document.getElementById("file").files[0];
        var formData = new FormData();
        formData.append("userNo", userNo);
        formData.append("file", file);
        $.ajax({
            url: "http://localhost:5761/lottery-system-system/system/api/auth/upload/imag",
            // url: "http://localhost:5730/system/api/upload/headImag",
            type: 'POST',
            beforeSend: function (XMLHttpRequest) {
                XMLHttpRequest.setRequestHeader("token", token);
            },
            data: formData,
            cache: false,
            contentType: false,
            processData: false,
            async: false,
            success: function (result) {
                // console.log(result);
                if (result.code == 200) {
                    url = result.data;
                    //预览图片
                    $("#img").attr("src", url);
                }
            }
        });
    });

    //获取个性签名的新值
    $("#info").change(function () {
        info = $("#info").val();
    });

    //点击更新
    $("#update").click(function () {
        if (url != null || info != null) {
            //保存
            console.log("save");
            var userExt = {
                userNo: $("#userNo").val(),
                headImagUrl: url,
                info: info
            };
            // console.log(userExt);
            $.ajax({
                url: "http://localhost:5761/lottery-system-user/user/api/auth/userext/save",
                type: "POST",
                beforeSend: function (XMLHttpRequest) {
                    XMLHttpRequest.setRequestHeader("token", token);
                },
                contentType: "application/json;charset=UTF-8",
                dataType: "JSON",
                data: JSON.stringify(userExt),
                success: function (result) {
                    console.log(result);
                    window.location.reload();
                }
            });
        } else {
            alert("无任何改动，无需更新！！！")
        }
    });



</script>

</body>
</html>